package cn.wolfcode.consumer._04_consumer_way;

import org.apache.rocketmq.client.consumer.DefaultMQPullConsumer;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.PullResult;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.common.message.MessageQueue;

import java.util.List;

/**
 * 更改消息获取方式为pull
 */
public class Consumer {
    public static void main(String[] args) throws Exception {
        //1.创建一个消费者(被动的由broker推送得到消息)
        DefaultMQPullConsumer consumer = new DefaultMQPullConsumer("wolfcode_consumer");//-<------<
        //2.设置nameSrv地址
        consumer.setNamesrvAddr("127.0.0.1:9876");
        //3.启动消费者
        consumer.start();
        //4.主动去broker拉取信息
        PullResult pull = consumer.pull(new MessageQueue("04-consumer-way", "broker-a", 3), "*", 0, 10);
        List<MessageExt> list = pull.getMsgFoundList();
        //5.拿到消息列表的集合
        for (MessageExt messageExt : list) {
            System.out.println("消息内容是:"+new String(messageExt.getBody()));
        }

    }
}
